<?php
/**
 * @package    Joomla.Tutorials
 * @subpackage Components
 * @link       http://docs.joomla.org/Category:Development
 * @license    GNU/GPL
 */
 
// no direct access
 
defined( '_JEXEC' ) or die( 'Restricted access' );
 
jimport( 'joomla.application.component.view');
 
/**
 * HTML View class for the HelloWorld Component
 *
 * @package    HelloWorld
 */
 
class NvViewFb extends JView
{
    function display($tpl = null)
    {		
		$document 	=& JFactory::getDocument();		
		$document->addStyleSheet('components/com_nv/assets/css/front.css');
		$document->addStyleSheet('components/com_nv/assets/css/liveval.css');
		$document->addScript('components/com_nv/assets/js/livevalidation.js');
		$document->addScript('components/com_nv/assets/js/jquery-1.3.2.js');
		$document->addScript('components/com_nv/assets/js/jquery.blockUI.js');
		
		$result = JRequest::getVar( 'result' );
		
		// Check if there need a results
		if($result)
		{
			//get the input string
			$str = JRequest::getVar( 'str' );
			$string = $this->utf8_strip_non_ascii_ctrl($str);
			
			//Get Data from DB
			$db =& JFactory::getDBO();
			$query = "SELECT * FROM #__fb_nusaview WHERE nama_objek LIKE '%".trim($string)."%' ORDER BY date_in DESC";
			
			$db->setQuery( $query );
			$rows = $db->loadObjectList();
			
			if ($db->getErrorNum())
			{
				echo $db->stderr();
				return false;
			}//end of if with error
			
			$fb = $rows;
			
			//send variables to views default
			$this->assignRef( 'str', $str );
			$this->assignRef( 'fb', $fb );
			
		}//end of if with result
		
		$this->assignRef( 'result', $result );
 
        parent::display($tpl);
    }//end of function display

	function utf8_strip_non_ascii_ctrl($str) {
		ob_start();
		while ( preg_match('/^([\x09\x0A\x0D\x20-\x7E]+)|([^\x09\x0A\x0D\x20-\x7E]+)/S', $str, $matches) ) {
			if ( !isset($matches[2]) ) {
				 echo $matches[0];
			}
			$str = substr($str, strlen($matches[0]));
		}
		$result = ob_get_contents();
		ob_end_clean();
		return addslashes($result);
	}//end
	
}
?>
